Skip to content

[iceberg] Require incremental resync after rebuilding metadata - #11421

Open
sundapeng wants to merge 3 commits into
apache:masterfrom
sundapeng:iceberg-without-base-commit-kind
Open

sundapeng wants to merge 3 commits into
apache:masterfrom
sundapeng:iceberg-without-base-commit-kind

Conversation

@sundapeng

@sundapeng sundapeng commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Purpose

An Iceberg metadata rebuild exports the complete current file set. The rebuilt snapshot used to claim the preceding Paimon snapshot ID as its Iceberg parent even though the rebuilt metadata contains no prior Iceberg snapshot. An append scan can accept a checkpoint at that missing parent and replay the full export as a delta.

Publish a full export as the root of a new Iceberg snapshot history. A reader with a checkpoint from before the rebuild must read a full snapshot and resume on the new history. Keep the initial export readable as an append, including when the first Paimon write is an overwrite. The normal publication path with a usable Iceberg base keeps its existing behavior.

Tests

  • Used a real Iceberg incremental append scan to verify that a full compaction rebuild rejects both old checkpoints and still exposes the expected rows through a full scan. The fixture disables deletion vectors and leaves the input records invisible to Iceberg until compaction.
  • Verified that an initial append and an initial overwrite both expose their first files to incremental append scans.
  • The previous PR implementation failed both review regressions.
  • Ran IcebergCompatibilityTest and spotless:check for paimon-core.

API and Format

Existing Iceberg metadata fields encode the new snapshot history boundary.

Documentation

Documented how an incremental reader resumes after an Iceberg metadata rebuild.

…ata rebuild

When Iceberg metadata is recreated from scratch (no base metadata file:
first snapshot after enabling the compatibility, metadata directory
deleted or expired, or an Iceberg format-version change),
createMetadataWithoutBase hardcoded the snapshot summary operation to
"append" even when the triggering Paimon snapshot was a COMPACT or
OVERWRITE commit. The with-base path already derives REPLACE/OVERWRITE
from the commit kind, so the two paths disagreed: incremental Iceberg
readers that key off the operation replay a full rebuilt snapshot as
newly appended data and see duplicated rows.

Derive the operation from paimonSnapshot.commitKind() in the rebuild
path as well, mirroring createWithDeleteManifestFileMetas.
The rebuild test only pinned COMPACT -> "replace". Add an overwrite case
asserting that an overwrite commit rebuilds the metadata with the
"overwrite" operation, an append case pinning the "append" default of
the first without-base export, and an existence check that the metadata
wipe really removed the directory so the with-base path cannot silently
cover the rebuild.

@JingsongLi JingsongLi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I verified both cases against the merge base using Iceberg's incremental append scan.

// the full table must do the same, or incremental consumers replay it as new data
String operation = IcebergSnapshotSummary.APPEND.operation();
if (paimonSnapshot.commitKind() == Snapshot.CommitKind.COMPACT) {
operation = IcebergSnapshotSummary.REPLACE.operation();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a primary-key table with deletion vectors disabled, publish an empty Iceberg snapshot, append rows that stay in L0, delete the Iceberg metadata directory, and run a full compaction. The rebuilt snapshot exposes the new rows in a full scan. An incremental append scan using fromSnapshotExclusive(previousSnapshotId) skips them because the snapshot is marked replace. Reserve replace for compactions that preserve the Iceberg-visible row set. If the prior Iceberg state is unavailable, make the rebuild require a full resync.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 863101c. The rebuild no longer describes itself as an incremental delta at all: createMetadataWithoutBase now publishes the full export as an append snapshot with no parent, so a metadata rebuild starts a new Iceberg snapshot history. A reader holding a pre-rebuild checkpoint gets Iceberg's own ancestor validation instead of silently skipped rows — newIncrementalAppendScan().fromSnapshotExclusive(oldCheckpoint) throws IllegalArgumentException ("... not a parent ancestor ...") and the reader must resync from a full scan. This also retires the commit-kind-derived replace/overwrite marking from the previous revision, which as you demonstrated would have hidden the L0 rows from the incremental scan.

testWithoutBaseRebuildRequiresIncrementalResync reproduces your exact sequence with the Iceberg client (primary-key table, deletion vectors disabled, empty Iceberg snapshot, L0 appends, metadata wipe asserted, full compaction): the full scan still returns all rows, the rebuilt snapshot has a null parent, and both pre-rebuild checkpoints are rejected. Red on the previous head: the same test did not raise on fromSnapshotExclusive(previousHead). Green: IcebergCompatibilityTest 65/65.

if (paimonSnapshot.commitKind() == Snapshot.CommitKind.COMPACT) {
operation = IcebergSnapshotSummary.REPLACE.operation();
} else if (paimonSnapshot.commitKind() == Snapshot.CommitKind.OVERWRITE) {
operation = IcebergSnapshotSummary.OVERWRITE.operation();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a new append table with Iceberg publishing enabled, use INSERT OVERWRITE for the first write. The Iceberg snapshot has no parent and only adds data files. Marking it overwrite makes newIncrementalAppendScan() skip the inserted rows. Keep append for the initial snapshot when it only adds data files.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in the same commit: a full export always publishes as append, including when the first Paimon write is an INSERT OVERWRITE, so an initial snapshot that only adds data files stays readable by newIncrementalAppendScan. testInitialIcebergSnapshotCanBeReadAsAppend covers both a plain first insert and a first overwrite and verifies with the Iceberg client that the incremental append scan plans the inserted files (record count asserted). Red on the previous head (overwrite operation): the overwrite variant found no files in the incremental scan. The resync requirement is documented in docs/docs/iceberg/index.md.

A full export cannot serve as an incremental delta from a missing parent. Publish it without a parent so a reader with an old checkpoint must resync. Preserve append semantics for an initial export, including a first overwrite, and verify both behaviors with the Iceberg client.
@sundapeng sundapeng changed the title [iceberg] Derive snapshot summary operation from commit kind in metadata rebuild [iceberg] Require incremental resync after rebuilding metadata Nov 25, 2026
@sundapeng sundapeng closed this Nov 25, 2026
@sundapeng sundapeng reopened this Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants